﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using CRM.Entity;

using CRM.BLL;
using DP.Web.UI.Controls;
using DP.Web.UI;
using DP.Common;

namespace CRM.Web.Pop
{
    public partial class HistoryWork : Common.PageBase
    {
        private UserLoginInfo _userLoginInfo;
        public string RepairCaseModifyUrl = "~/RepairCaseManage/Modify.aspx?CASEID={0}&PageTarget=Opener";
        public string ConsultingCaseModifyUrl = "~/ConsultingCaseManage/Modify.aspx?CASEID={0}&PageTarget=Opener";
        public string ComplaintCaseModifyUrl = "~/ComplaintCaseManage/Modify.aspx?CASEID={0}&PageTarget=Opener";
		T_REPAIRCASE_BLL repairCaseBll = new T_REPAIRCASE_BLL();
        private T_CONSULTINGCASE_BLL consultingCaseBll = new T_CONSULTINGCASE_BLL();
        private T_COMPLAINTCASE_BLL complaintCaseBll = new T_COMPLAINTCASE_BLL();
        private T_WORKORDERSTATUS_BLL workOrderStatusBll = new T_WORKORDERSTATUS_BLL();
        /// <summary>
        /// 配置
        /// </summary>
        protected T_CONFIG_BLL configBll = new T_CONFIG_BLL();

			
		protected override void OnInit(EventArgs e)
        {
            base.VerificationRight = false;
            base.OnInit(e);
            _userLoginInfo = UserLoginInfo.GetLoginInfo();
            PageHelper.SetPrePageUrl(this.Page);
			
        }
		
        protected void Page_Load(object sender, EventArgs e)
        {
			if (!IsPostBack)
            {
                GetUrlQueryToControl();
				gvDataBinding();				
            }			
        }

        /// <summary>
        /// 获取 URL 上的参数存入当页面 控件中。
        /// </summary>
        private void GetUrlQueryToControl()
        {
            PageHelper.GetUrlQueryToControl(this.Page);
        }
		
		/// <summary>
        /// 生成查询条件字符串
        /// </summary>
        private StringBuilder GenerationRepairCaseSQLString()
		{
			StringBuilder sql = new StringBuilder();
            #region MyRegion
            if (!String.IsNullOrEmpty(Request.QueryString["CASEID"]))
            {
                //sql.Append(" and CASEID like '%" + Request.QueryString["CASEID"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLER"]))
            {
                sql.Append(" and CALLER like '%" + Request.QueryString["CALLER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLED"]))
            {
                //sql.Append(" and CALLED like '%" + Request.QueryString["CALLED"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLID"]))
            {
                //sql.Append(" and CALLID = '" + Request.QueryString["CALLID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECORDCODE"]))
            {
                //sql.Append(" and RECORDCODE like '%" + Request.QueryString["RECORDCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLTYPE"]))
            {
                //sql.Append(" and CALLTYPE like '%" + Request.QueryString["CALLTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERID"]))
            {
                //sql.Append(" and CUSTOMERID = '" + Request.QueryString["CUSTOMERID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERNAME"]))
            {
                sql.Append(" and CUSTOMERNAME like '%" + Request.QueryString["CUSTOMERNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COUNTRY"]))
            {
                sql.Append(" and COUNTRY like '%" + Request.QueryString["COUNTRY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROVINCE"]))
            {
                sql.Append(" and PROVINCE like '%" + Request.QueryString["PROVINCE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PREFECTURECITY"]))
            {
                sql.Append(" and PREFECTURECITY like '%" + Request.QueryString["PREFECTURECITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CITY"]))
            {
                sql.Append(" and CITY like '%" + Request.QueryString["CITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VILLAGETOWN"]))
            {
                sql.Append(" and VILLAGETOWN like '%" + Request.QueryString["VILLAGETOWN"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VILLAGE"]))
            {
                sql.Append(" and VILLAGE like '%" + Request.QueryString["VILLAGE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["GROUPTEAM"]))
            {
                sql.Append(" and GROUPTEAM like '%" + Request.QueryString["GROUPTEAM"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ADDRESS"]))
            {
                sql.Append(" and ADDRESS like '%" + Request.QueryString["ADDRESS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FIRSTCONTACTTEL"]))
            {
                sql.Append(" and FIRSTCONTACTTEL like '%" + Request.QueryString["FIRSTCONTACTTEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BRAND"]))
            {
                sql.Append(" and BRAND like '%" + Request.QueryString["BRAND"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VEHICLETYPE"]))
            {
                sql.Append(" and VEHICLETYPE like '%" + Request.QueryString["VEHICLETYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VINCODE"]))
            {
                sql.Append(" and upper(VINCODE) like '%" + Request.QueryString["VINCODE"].ToUpper() + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PRODUCTCODE"]))
            {
                sql.Append(" and PRODUCTCODE like '%" + Request.QueryString["PRODUCTCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERIES"]))
            {
                sql.Append(" and SERIES like '%" + Request.QueryString["SERIES"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MODELS"]))
            {
                sql.Append(" and MODELS like '%" + Request.QueryString["MODELS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMODEL"]))
            {
                sql.Append(" and ENGINEMODEL like '%" + Request.QueryString["ENGINEMODEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMANUFACTURERS"]))
            {
                sql.Append(" and ENGINEMANUFACTURERS like '%" + Request.QueryString["ENGINEMANUFACTURERS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAULTSYSTEM"]))
            {
                sql.Append(" and FAULTSYSTEM like '%" + Request.QueryString["FAULTSYSTEM"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAILEDPARTSASSEMBLY"]))
            {
                sql.Append(" and FAILEDPARTSASSEMBLY like '%" + Request.QueryString["FAILEDPARTSASSEMBLY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAILUREPARTS"]))
            {
                sql.Append(" and FAILUREPARTS like '%" + Request.QueryString["FAILUREPARTS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAULTCODES"]))
            {
                sql.Append(" and FAULTCODES like '%" + Request.QueryString["FAULTCODES"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SYMPTOM"]))
            {
                sql.Append(" and SYMPTOM like '%" + Request.QueryString["SYMPTOM"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SYMPTOMDESCRIPTION"]))
            {
                sql.Append(" and SYMPTOMDESCRIPTION like '%" + Request.QueryString["SYMPTOMDESCRIPTION"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAILURELEVEL"]))
            {
                sql.Append(" and FAILURELEVEL like '%" + Request.QueryString["FAILURELEVEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAILUREANALYSIS"]))
            {
                sql.Append(" and FAILUREANALYSIS like '%" + Request.QueryString["FAILUREANALYSIS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["STATUS"]))
            {
                sql.Append(" and STATUS like '%" + Request.QueryString["STATUS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["HANDLING"]))
            {
                sql.Append(" and HANDLING like '%" + Request.QueryString["HANDLING"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["APPROACH"]))
            {
                sql.Append(" and APPROACH like '%" + Request.QueryString["APPROACH"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RESULTS"]))
            {
                sql.Append(" and RESULTS like '%" + Request.QueryString["RESULTS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SEATSSUMMARY"]))
            {
                sql.Append(" and SEATSSUMMARY like '%" + Request.QueryString["SEATSSUMMARY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAILUREOCCURS"]))
            {
                sql.Append(" and FAILUREOCCURS like '%" + Request.QueryString["FAILUREOCCURS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["GPSADDRESS"]))
            {
                sql.Append(" and GPSADDRESS like '%" + Request.QueryString["GPSADDRESS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATETIMEBegin"]))
            {
                sql.Append(" and CREATETIME >= '" + Request.QueryString["CREATETIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATETIMEEnd"]))
            {
                sql.Append(" and CREATETIME < '" + Request.QueryString["CREATETIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATEPEOPLEID"]))
            {
                sql.Append(" and CREATEPEOPLEID = '" + Request.QueryString["CREATEPEOPLEID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATEPEOPLE"]))
            {
                sql.Append(" and CREATEPEOPLE like '%" + Request.QueryString["CREATEPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYPEOPLEID"]))
            {
                sql.Append(" and LASTMODIFYPEOPLEID = '" + Request.QueryString["LASTMODIFYPEOPLEID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYPEOPLE"]))
            {
                sql.Append(" and LASTMODIFYPEOPLE like '%" + Request.QueryString["LASTMODIFYPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REMARK"]))
            {
                sql.Append(" and REMARK like '%" + Request.QueryString["REMARK"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MARKETDEPARTMENTID"]))
            {
                sql.Append(" and MARKETDEPARTMENTID = '" + Request.QueryString["MARKETDEPARTMENTID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MARKETDEPARTMENTCODE"]))
            {
                sql.Append(" and MARKETDEPARTMENTCODE like '%" + Request.QueryString["MARKETDEPARTMENTCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MARKETDEPARTMENTNAME"]))
            {
                sql.Append(" and MARKETDEPARTMENTNAME like '%" + Request.QueryString["MARKETDEPARTMENTNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DISPATCHINGOBJECTTYPE"]))
            {
                sql.Append(" and DISPATCHINGOBJECTTYPE like '%" + Request.QueryString["DISPATCHINGOBJECTTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DISPATCHINGOBJECT"]))
            {
                sql.Append(" and DISPATCHINGOBJECT like '%" + Request.QueryString["DISPATCHINGOBJECT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DISPATCHINGTIMEBegin"]))
            {
                sql.Append(" and DISPATCHINGTIME >= '" + Request.QueryString["DISPATCHINGTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DISPATCHINGTIMEEnd"]))
            {
                sql.Append(" and DISPATCHINGTIME < '" + Request.QueryString["DISPATCHINGTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FOLLOWUPTIMEBegin"]))
            {
                sql.Append(" and FOLLOWUPTIME >= '" + Request.QueryString["FOLLOWUPTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FOLLOWUPTIMEEnd"]))
            {
                sql.Append(" and FOLLOWUPTIME < '" + Request.QueryString["FOLLOWUPTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FOLLOWUPCONTENT"]))
            {
                sql.Append(" and FOLLOWUPCONTENT like '%" + Request.QueryString["FOLLOWUPCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGTIMEBegin"]))
            {
                sql.Append(" and PROCESSINGTIME >= '" + Request.QueryString["PROCESSINGTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGTIMEEnd"]))
            {
                sql.Append(" and PROCESSINGTIME < '" + Request.QueryString["PROCESSINGTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGCONTENT"]))
            {
                sql.Append(" and PROCESSINGCONTENT like '%" + Request.QueryString["PROCESSINGCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CLOSETIMEBegin"]))
            {
                sql.Append(" and CLOSETIME >= '" + Request.QueryString["CLOSETIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CLOSETIMEEnd"]))
            {
                sql.Append(" and CLOSETIME < '" + Request.QueryString["CLOSETIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CLOSECONTENT"]))
            {
                sql.Append(" and CLOSECONTENT like '%" + Request.QueryString["CLOSECONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["TURNTIMEBegin"]))
            {
                sql.Append(" and TURNTIME >= '" + Request.QueryString["TURNTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["TURNTIMEEnd"]))
            {
                sql.Append(" and TURNTIME < '" + Request.QueryString["TURNTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["TURNCONTENT"]))
            {
                sql.Append(" and TURNCONTENT like '%" + Request.QueryString["TURNCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["TODOREMINDERTIMEBegin"]))
            {
                sql.Append(" and TODOREMINDERTIME >= '" + Request.QueryString["TODOREMINDERTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["TODOREMINDERTIMEEnd"]))
            {
                sql.Append(" and TODOREMINDERTIME < '" + Request.QueryString["TODOREMINDERTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REVISITINGTIMEBegin"]))
            {
                sql.Append(" and REVISITINGTIME >= '" + Request.QueryString["REVISITINGTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REVISITINGTIMEEnd"]))
            {
                sql.Append(" and REVISITINGTIME < '" + Request.QueryString["REVISITINGTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECEIVETIMEBegin"]))
            {
                sql.Append(" and RECEIVETIME >= '" + Request.QueryString["RECEIVETIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECEIVETIMEEnd"]))
            {
                sql.Append(" and RECEIVETIME < '" + Request.QueryString["RECEIVETIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECEIVECONTENT"]))
            {
                sql.Append(" and RECEIVECONTENT like '%" + Request.QueryString["RECEIVECONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECEIVEPEOPLE"]))
            {
                sql.Append(" and RECEIVEPEOPLE like '%" + Request.QueryString["RECEIVEPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEPARTURETIMEBegin"]))
            {
                sql.Append(" and DEPARTURETIME >= '" + Request.QueryString["DEPARTURETIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEPARTURETIMEEnd"]))
            {
                sql.Append(" and DEPARTURETIME < '" + Request.QueryString["DEPARTURETIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEPARTURECONTENT"]))
            {
                sql.Append(" and DEPARTURECONTENT like '%" + Request.QueryString["DEPARTURECONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEPARTUREPEOPLE"]))
            {
                sql.Append(" and DEPARTUREPEOPLE like '%" + Request.QueryString["DEPARTUREPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ARRIVALTIMEBegin"]))
            {
                sql.Append(" and ARRIVALTIME >= '" + Request.QueryString["ARRIVALTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ARRIVALTIMEEnd"]))
            {
                sql.Append(" and ARRIVALTIME < '" + Request.QueryString["ARRIVALTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ARRIVALCONTENT"]))
            {
                sql.Append(" and ARRIVALCONTENT like '%" + Request.QueryString["ARRIVALCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ARRIVALPEOPLE"]))
            {
                sql.Append(" and ARRIVALPEOPLE like '%" + Request.QueryString["ARRIVALPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COMPLETEDTIMEBegin"]))
            {
                sql.Append(" and COMPLETEDTIME >= '" + Request.QueryString["COMPLETEDTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COMPLETEDTIMEEnd"]))
            {
                sql.Append(" and COMPLETEDTIME < '" + Request.QueryString["COMPLETEDTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COMPLETEDCONTENT"]))
            {
                sql.Append(" and COMPLETEDCONTENT like '%" + Request.QueryString["COMPLETEDCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COMPLETEDPEOPLE"]))
            {
                sql.Append(" and COMPLETEDPEOPLE like '%" + Request.QueryString["COMPLETEDPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERVICENUMBER"]))
            {
                sql.Append(" and SERVICENUMBER like '%" + Request.QueryString["SERVICENUMBER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MILEAGE"]))
            {
                sql.Append(" and MILEAGE like '%" + Request.QueryString["MILEAGE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PLACEMETHOD"]))
            {
                sql.Append(" and PLACEMETHOD like '%" + Request.QueryString["PLACEMETHOD"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERVICEFEE"]))
            {
                sql.Append(" and SERVICEFEE like '%" + Request.QueryString["SERVICEFEE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERVICEHOURS"]))
            {
                sql.Append(" and SERVICEHOURS like '%" + Request.QueryString["SERVICEHOURS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REPAIRPARTS"]))
            {
                sql.Append(" and REPAIRPARTS like '%" + Request.QueryString["REPAIRPARTS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["HANDLINGINSTRUCTIONS"]))
            {
                sql.Append(" and HANDLINGINSTRUCTIONS like '%" + Request.QueryString["HANDLINGINSTRUCTIONS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PRODUCTSATISFACTION"]))
            {
                sql.Append(" and PRODUCTSATISFACTION like '%" + Request.QueryString["PRODUCTSATISFACTION"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERVICESATISFACTION"]))
            {
                sql.Append(" and SERVICESATISFACTION like '%" + Request.QueryString["SERVICESATISFACTION"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITTIMEBegin"]))
            {
                sql.Append(" and VISITTIME >= '" + Request.QueryString["VISITTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITTIMEEnd"]))
            {
                sql.Append(" and VISITTIME < '" + Request.QueryString["VISITTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITCOMPLETEDTIMEBegin"]))
            {
                sql.Append(" and VISITCOMPLETEDTIME >= '" + Request.QueryString["VISITCOMPLETEDTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITCOMPLETEDTIMEEnd"]))
            {
                sql.Append(" and VISITCOMPLETEDTIME < '" + Request.QueryString["VISITCOMPLETEDTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITREMARK"]))
            {
                sql.Append(" and VISITREMARK like '%" + Request.QueryString["VISITREMARK"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONID"]))
            {
                sql.Append(" and BUSINESSDIVISIONID = '" + Request.QueryString["BUSINESSDIVISIONID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONNAME"]))
            {
                sql.Append(" and BUSINESSDIVISIONNAME like '%" + Request.QueryString["BUSINESSDIVISIONNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONCODE"]))
            {
                sql.Append(" and BUSINESSDIVISIONCODE like '%" + Request.QueryString["BUSINESSDIVISIONCODE"] + "%'");
            }
            #endregion

            if (sql.Length == 0)
            {
                return sql;
            }
            if (!UserLoginInfo.IsAdministrator())
            {
                //操作员当前事业务数据
                sql.Append(" and BUSINESSDIVISIONCODE = '" + _userLoginInfo.UserEntity.BUSINESSDIVISIONCODE.Trim() + "'");

                switch (UserLoginInfo.GetCurrentUserType())
                {
                    case UserType.中心部门:
                        {
                            
                        }
                        break;
                    case UserType.供应商:
                    case UserType.市场部:
                    case UserType.服务商:
                    case UserType.经销商:
                        {
                            sql.Append(String.Format(" and ProcessingObjectType = '{0}' ", _userLoginInfo.UserEntity.USERTYPE.Trim()));
                            sql.Append(String.Format(" and ProcessingDepartmentID = '{0}' ", _userLoginInfo.UserEntity.DEPARTMENTID));
                            //sql.Append(caBll.GenerateContentAuthorityConditions(_userLoginInfo, "ProcessingUserID", true));
                        }
                        break;
                }
            }
		    return sql;
			
		}

        /// <summary>
        /// 生成查询条件字符串
        /// </summary>
        private StringBuilder GenerationConsultingCaseSQLString()
        {
            StringBuilder sql = new StringBuilder();
            #region MyRegion
            if (!String.IsNullOrEmpty(Request.QueryString["CASEID"]))
            {
                //sql.Append(" and CASEID like '%" + Request.QueryString["CASEID"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLER"]))
            {
                sql.Append(String.Format(" and ( CALLER = '{0}' or FirstContactTel = '{0}' or OwnersMobilePhone = '{0}' or OwnersOfficePhone = '{0}' or OwnersHomePhone = '{0}' )", Request.QueryString["CALLER"].ToString()));
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLED"]))
            {
                //sql.Append(" and CALLED like '%" + Request.QueryString["CALLED"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLID"]))
            {
                //sql.Append(" and CALLID = '" + Request.QueryString["CALLID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECORDCODE"]))
            {
                //sql.Append(" and RECORDCODE like '%" + Request.QueryString["RECORDCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLTYPE"]))
            {
                //sql.Append(" and CALLTYPE like '%" + Request.QueryString["CALLTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERID"]))
            {
                //sql.Append(" and CUSTOMERID = '" + Request.QueryString["CUSTOMERID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERNAME"]))
            {
                sql.Append(" and CUSTOMERNAME like '%" + Request.QueryString["CUSTOMERNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FIRSTCONTACTTEL"]))
            {
                sql.Append(" and FIRSTCONTACTTEL like '%" + Request.QueryString["FIRSTCONTACTTEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ADDRESS"]))
            {
                sql.Append(" and ADDRESS like '%" + Request.QueryString["ADDRESS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COUNTRY"]))
            {
                sql.Append(" and COUNTRY like '%" + Request.QueryString["COUNTRY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROVINCE"]))
            {
                sql.Append(" and PROVINCE like '%" + Request.QueryString["PROVINCE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PREFECTURECITY"]))
            {
                sql.Append(" and PREFECTURECITY like '%" + Request.QueryString["PREFECTURECITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CITY"]))
            {
                sql.Append(" and CITY like '%" + Request.QueryString["CITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VILLAGETOWN"]))
            {
                sql.Append(" and VILLAGETOWN like '%" + Request.QueryString["VILLAGETOWN"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VILLAGE"]))
            {
                sql.Append(" and VILLAGE like '%" + Request.QueryString["VILLAGE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["GROUPTEAM"]))
            {
                sql.Append(" and GROUPTEAM like '%" + Request.QueryString["GROUPTEAM"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CONSULTINGTYPE"]))
            {
                sql.Append(" and CONSULTINGTYPE like '%" + Request.QueryString["CONSULTINGTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VINCODE"]))
            {
                sql.Append(" and VINCODE like '%" + Request.QueryString["VINCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BRAND"]))
            {
                sql.Append(" and BRAND like '%" + Request.QueryString["BRAND"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VEHICLETYPE"]))
            {
                sql.Append(" and VEHICLETYPE like '%" + Request.QueryString["VEHICLETYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PRODUCTCODE"]))
            {
                sql.Append(" and PRODUCTCODE like '%" + Request.QueryString["PRODUCTCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERIES"]))
            {
                sql.Append(" and SERIES like '%" + Request.QueryString["SERIES"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MODELS"]))
            {
                sql.Append(" and MODELS like '%" + Request.QueryString["MODELS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMODEL"]))
            {
                sql.Append(" and ENGINEMODEL like '%" + Request.QueryString["ENGINEMODEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMANUFACTURERS"]))
            {
                sql.Append(" and ENGINEMANUFACTURERS like '%" + Request.QueryString["ENGINEMANUFACTURERS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CONSULTINGCONTENT"]))
            {
                sql.Append(" and CONSULTINGCONTENT like '%" + Request.QueryString["CONSULTINGCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["APPROACH"]))
            {
                sql.Append(" and APPROACH like '%" + Request.QueryString["APPROACH"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["STATUS"]))
            {
                sql.Append(" and STATUS like '%" + Request.QueryString["STATUS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RESULTS"]))
            {
                sql.Append(" and RESULTS like '%" + Request.QueryString["RESULTS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REMINDERTIME"]))
            {
                sql.Append(" and REMINDERTIME like '%" + Request.QueryString["REMINDERTIME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATETIMEBegin"]))
            {
                sql.Append(" and CREATETIME >= '" + Request.QueryString["CREATETIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATETIMEEnd"]))
            {
                sql.Append(" and CREATETIME < '" + Request.QueryString["CREATETIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATEPEOPLEID"]))
            {
                sql.Append(" and CREATEPEOPLEID = '" + Request.QueryString["CREATEPEOPLEID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATEPEOPLE"]))
            {
                sql.Append(" and CREATEPEOPLE like '%" + Request.QueryString["CREATEPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYPEOPLEID"]))
            {
                sql.Append(" and LASTMODIFYPEOPLEID = '" + Request.QueryString["LASTMODIFYPEOPLEID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYPEOPLE"]))
            {
                sql.Append(" and LASTMODIFYPEOPLE like '%" + Request.QueryString["LASTMODIFYPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REMARK"]))
            {
                sql.Append(" and REMARK like '%" + Request.QueryString["REMARK"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONID"]))
            {
                sql.Append(" and BUSINESSDIVISIONID = '" + Request.QueryString["BUSINESSDIVISIONID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONNAME"]))
            {
                sql.Append(" and BUSINESSDIVISIONNAME like '%" + Request.QueryString["BUSINESSDIVISIONNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONCODE"]))
            {
                sql.Append(" and BUSINESSDIVISIONCODE like '%" + Request.QueryString["BUSINESSDIVISIONCODE"] + "%'");
            }
            #endregion

            if (sql.Length == 0)
            {
                return sql;
            }
            if (!UserLoginInfo.IsAdministrator())
            {
                //操作员当前事业务数据
                sql.Append(" and BUSINESSDIVISIONCODE = '" + _userLoginInfo.UserEntity.BUSINESSDIVISIONCODE.Trim() + "'");

                switch (UserLoginInfo.GetCurrentUserType())
                {
                    case UserType.中心部门:
                        {

                        }
                        break;
                    case UserType.供应商:
                    case UserType.市场部:
                    case UserType.服务商:
                    case UserType.经销商:
                        {
                            sql.Append(String.Format(" and CREATEUSERTYPE = '{0}' ", _userLoginInfo.UserEntity.USERTYPE.Trim()));
                            sql.Append(String.Format(" and CREATEDEPARTMENTID = '{0}' ", _userLoginInfo.UserEntity.DEPARTMENTID));
                        }
                        break;
                }
            }

            return sql;

        }

        /// <summary>
        /// 生成查询条件字符串
        /// </summary>
        private StringBuilder GenerationComplaintCaseSQLString()
        {
            StringBuilder sql = new StringBuilder();
            #region MyRegion
            if (!String.IsNullOrEmpty(Request.QueryString["CASEID"]))
            {
                //sql.Append(" and CASEID like '%" + Request.QueryString["CASEID"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLER"]))
            {
                sql.Append(" and CALLER like '%" + Request.QueryString["CALLER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLED"]))
            {
                //sql.Append(" and CALLED like '%" + Request.QueryString["CALLED"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLID"]))
            {
                //sql.Append(" and CALLID = '" + Request.QueryString["CALLID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECORDCODE"]))
            {
                //sql.Append(" and RECORDCODE like '%" + Request.QueryString["RECORDCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLTYPE"]))
            {
                //sql.Append(" and CALLTYPE like '%" + Request.QueryString["CALLTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERID"]))
            {
                //sql.Append(" and CUSTOMERID = '" + Request.QueryString["CUSTOMERID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERNAME"]))
            {
                sql.Append(" and CUSTOMERNAME like '%" + Request.QueryString["CUSTOMERNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FIRSTCONTACTTEL"]))
            {
                sql.Append(" and FIRSTCONTACTTEL like '%" + Request.QueryString["FIRSTCONTACTTEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ADDRESS"]))
            {
                sql.Append(" and ADDRESS like '%" + Request.QueryString["ADDRESS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COUNTRY"]))
            {
                sql.Append(" and COUNTRY like '%" + Request.QueryString["COUNTRY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROVINCE"]))
            {
                sql.Append(" and PROVINCE like '%" + Request.QueryString["PROVINCE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PREFECTURECITY"]))
            {
                sql.Append(" and PREFECTURECITY like '%" + Request.QueryString["PREFECTURECITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CITY"]))
            {
                sql.Append(" and CITY like '%" + Request.QueryString["CITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VILLAGETOWN"]))
            {
                sql.Append(" and VILLAGETOWN like '%" + Request.QueryString["VILLAGETOWN"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VILLAGE"]))
            {
                sql.Append(" and VILLAGE like '%" + Request.QueryString["VILLAGE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["GROUPTEAM"]))
            {
                sql.Append(" and GROUPTEAM like '%" + Request.QueryString["GROUPTEAM"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VEHICLELOCATION"]))
            {
                sql.Append(" and VEHICLELOCATION like '%" + Request.QueryString["VEHICLELOCATION"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["GPSADDRESS"]))
            {
                sql.Append(" and GPSADDRESS like '%" + Request.QueryString["GPSADDRESS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CONSULTINGTYPE"]))
            {
                sql.Append(" and CONSULTINGTYPE like '%" + Request.QueryString["CONSULTINGTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VINCODE"]))
            {
                sql.Append(" and VINCODE like '%" + Request.QueryString["VINCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BRAND"]))
            {
                sql.Append(" and BRAND like '%" + Request.QueryString["BRAND"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VEHICLETYPE"]))
            {
                sql.Append(" and VEHICLETYPE like '%" + Request.QueryString["VEHICLETYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PRODUCTCODE"]))
            {
                sql.Append(" and PRODUCTCODE like '%" + Request.QueryString["PRODUCTCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERIES"]))
            {
                sql.Append(" and SERIES like '%" + Request.QueryString["SERIES"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MODELS"]))
            {
                sql.Append(" and MODELS like '%" + Request.QueryString["MODELS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMODEL"]))
            {
                sql.Append(" and ENGINEMODEL like '%" + Request.QueryString["ENGINEMODEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMANUFACTURERS"]))
            {
                sql.Append(" and ENGINEMANUFACTURERS like '%" + Request.QueryString["ENGINEMANUFACTURERS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OBJECTTYPE"]))
            {
                sql.Append(" and OBJECTTYPE like '%" + Request.QueryString["OBJECTTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COMPLAINTOBJECT"]))
            {
                sql.Append(" and COMPLAINTOBJECT like '%" + Request.QueryString["COMPLAINTOBJECT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COMPLAINTTYPE"]))
            {
                sql.Append(" and COMPLAINTTYPE like '%" + Request.QueryString["COMPLAINTTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COMPLAINTCONTENT"]))
            {
                sql.Append(" and COMPLAINTCONTENT like '%" + Request.QueryString["COMPLAINTCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COMPLAINTLEVEL"]))
            {
                sql.Append(" and COMPLAINTLEVEL like '%" + Request.QueryString["COMPLAINTLEVEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["APPROACH"]))
            {
                sql.Append(" and APPROACH like '%" + Request.QueryString["APPROACH"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["HANDLING"]))
            {
                sql.Append(" and HANDLING like '%" + Request.QueryString["HANDLING"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["STATUS"]))
            {
                sql.Append(" and STATUS like '%" + Request.QueryString["STATUS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RESULTS"]))
            {
                sql.Append(" and RESULTS like '%" + Request.QueryString["RESULTS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATETIMEBegin"]))
            {
                sql.Append(" and CREATETIME >= '" + Request.QueryString["CREATETIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATETIMEEnd"]))
            {
                sql.Append(" and CREATETIME < '" + Request.QueryString["CREATETIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATEPEOPLEID"]))
            {
                sql.Append(" and CREATEPEOPLEID = '" + Request.QueryString["CREATEPEOPLEID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATEPEOPLE"]))
            {
                sql.Append(" and CREATEPEOPLE like '%" + Request.QueryString["CREATEPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYPEOPLEID"]))
            {
                sql.Append(" and LASTMODIFYPEOPLEID = '" + Request.QueryString["LASTMODIFYPEOPLEID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYPEOPLE"]))
            {
                sql.Append(" and LASTMODIFYPEOPLE like '%" + Request.QueryString["LASTMODIFYPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REMARK"]))
            {
                sql.Append(" and REMARK like '%" + Request.QueryString["REMARK"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERVICENUMBER"]))
            {
                sql.Append(" and SERVICENUMBER like '%" + Request.QueryString["SERVICENUMBER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MILEAGE"]))
            {
                sql.Append(" and MILEAGE like '%" + Request.QueryString["MILEAGE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PLACEMETHOD"]))
            {
                sql.Append(" and PLACEMETHOD like '%" + Request.QueryString["PLACEMETHOD"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERVICEFEE"]))
            {
                sql.Append(" and SERVICEFEE like '%" + Request.QueryString["SERVICEFEE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERVICEHOURS"]))
            {
                sql.Append(" and SERVICEHOURS like '%" + Request.QueryString["SERVICEHOURS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REPAIRPARTS"]))
            {
                sql.Append(" and REPAIRPARTS like '%" + Request.QueryString["REPAIRPARTS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["HANDLINGINSTRUCTIONS"]))
            {
                sql.Append(" and HANDLINGINSTRUCTIONS like '%" + Request.QueryString["HANDLINGINSTRUCTIONS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PRODUCTSATISFACTION"]))
            {
                sql.Append(" and PRODUCTSATISFACTION like '%" + Request.QueryString["PRODUCTSATISFACTION"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERVICESATISFACTION"]))
            {
                sql.Append(" and SERVICESATISFACTION like '%" + Request.QueryString["SERVICESATISFACTION"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITTIMEBegin"]))
            {
                sql.Append(" and VISITTIME >= '" + Request.QueryString["VISITTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITTIMEEnd"]))
            {
                sql.Append(" and VISITTIME < '" + Request.QueryString["VISITTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITCOMPLETEDTIMEBegin"]))
            {
                sql.Append(" and VISITCOMPLETEDTIME >= '" + Request.QueryString["VISITCOMPLETEDTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITCOMPLETEDTIMEEnd"]))
            {
                sql.Append(" and VISITCOMPLETEDTIME < '" + Request.QueryString["VISITCOMPLETEDTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITREMARK"]))
            {
                sql.Append(" and VISITREMARK like '%" + Request.QueryString["VISITREMARK"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONID"]))
            {
                sql.Append(" and BUSINESSDIVISIONID = '" + Request.QueryString["BUSINESSDIVISIONID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONNAME"]))
            {
                sql.Append(" and BUSINESSDIVISIONNAME like '%" + Request.QueryString["BUSINESSDIVISIONNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONCODE"]))
            {
                sql.Append(" and BUSINESSDIVISIONCODE like '%" + Request.QueryString["BUSINESSDIVISIONCODE"] + "%'");
            }
            #endregion


            if (sql.Length == 0)
            {
                return sql;
            }
            if (!UserLoginInfo.IsAdministrator())
            {
                //操作员当前事业务数据
                sql.Append(" and BUSINESSDIVISIONCODE = '" + _userLoginInfo.UserEntity.BUSINESSDIVISIONCODE.Trim() + "'");
                switch (UserLoginInfo.GetCurrentUserType())
                {
                    case UserType.中心部门:
                        {

                        }
                        break;
                    case UserType.供应商:
                    case UserType.市场部:
                    case UserType.服务商:
                    case UserType.经销商:
                        {
                            sql.Append(String.Format(" and ProcessingObjectType = '{0}' ", _userLoginInfo.UserEntity.USERTYPE.Trim()));
                            sql.Append(String.Format(" and ProcessingDepartmentID = '{0}' ", _userLoginInfo.UserEntity.DEPARTMENTID));
                            //sql.Append(caBll.GenerateContentAuthorityConditions(_userLoginInfo, "ProcessingUserID", true));
                        }
                        break;
                }
            }
            return sql;

        }
		
		/// <summary>
        /// 页面数据绑定
        /// </summary>
        private void gvDataBinding()
        {
            #region 查询条件字符串
            StringBuilder sqlRepairCase = GenerationRepairCaseSQLString();
            StringBuilder sqlConsultingCase = GenerationConsultingCaseSQLString();
            StringBuilder sqlComplaintCaseList = GenerationComplaintCaseSQLString();
            #endregion 
			
            List<T_REPAIRCASE_Entity> repairCaseList;
		    List<T_CONSULTINGCASE_Entity> consultingCaseList;
		    List<T_COMPLAINTCASE_Entity> complaintCaseList;
			
			//报修工单
            if (sqlRepairCase.Length == 0)
            {
                gvListRepair.DataSource = new  List<T_REPAIRCASE_Entity>();
                gvListRepair.DataKeyNames = new string[] { "CASEID", "ToDoReminderTime" };
                gvListRepair.DataBind();
            }
            else
            {
                gvListRepair.RecordCount = (int)repairCaseBll.GetCount(sqlRepairCase.ToString());
                repairCaseList = repairCaseBll.GetList(sqlRepairCase.ToString(), gvListRepair.CurrentPageIndex * gvListRepair.PageSize, gvListRepair.PageSize, gvListRepair.SortConditions);
                gvListRepair.DataSource = repairCaseList;
                gvListRepair.DataKeyNames = new string[] { "CASEID", "ToDoReminderTime" };
                gvListRepair.DataBind();
            }


            //报修工单
            if (sqlConsultingCase.Length == 0)
            {
                gvListConsulting.DataSource = new List<T_CONSULTINGCASE_Entity>();
                gvListConsulting.DataKeyNames = new string[] { "CASEID" };
                gvListConsulting.DataBind();
            }
            else
            {
                gvListConsulting.RecordCount = (int)consultingCaseBll.GetCount(sqlConsultingCase.ToString());
                consultingCaseList = consultingCaseBll.GetList(sqlConsultingCase.ToString(), gvListConsulting.CurrentPageIndex * gvListConsulting.PageSize, gvListConsulting.PageSize, gvListConsulting.SortConditions);
                gvListConsulting.DataSource = consultingCaseList;
                gvListConsulting.DataKeyNames = new string[] { "CASEID" };
                gvListConsulting.DataBind();
            }


            //投诉工单
            if (sqlComplaintCaseList.Length == 0)
            {
                gvListComplaint.DataSource = new  List<T_COMPLAINTCASE_Entity>();
                gvListComplaint.DataKeyNames = new string[] { "CASEID", "ToDoReminderTime" };
                gvListComplaint.DataBind();

            }
            else
            {
                gvListComplaint.RecordCount = (int)complaintCaseBll.GetCount(sqlComplaintCaseList.ToString());
                complaintCaseList = complaintCaseBll.GetList(sqlComplaintCaseList.ToString(), gvListComplaint.CurrentPageIndex * gvListComplaint.PageSize, gvListComplaint.PageSize, gvListComplaint.SortConditions);
                gvListComplaint.DataSource = complaintCaseList;
                gvListComplaint.DataKeyNames = new string[] { "CASEID", "ToDoReminderTime" };
                gvListComplaint.DataBind();
            }
        }
		
		protected void btnSearch_Click(object sender, EventArgs e)
        {
			string url = HttpContext.Current.Request.Url.AbsolutePath;
            PageHelper.GetControlToUrlQuery(this.Page, ref url);
            Response.Redirect(url);								
        }
		
		#region GridView 事件
        /// <summary>
        /// GridView 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
			

        }

        /// <summary>
        /// GridView 行数据绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            string temp = string.Empty;
            switch (e.Row.RowType)
            {
                case DataControlRowType.DataRow:
                    {
						GridView gv = (sender as GridView);
                        for (int i = 0; i < gv.Columns.Count; i++)
                        {
                            TemplateField tf = gv.Columns[i] as TemplateField;
                            if (tf != null)
                            {
                                #region 存储值 转换成  显示值
                                switch (tf.HeaderText)
                                {
                                    case "操作":
                                        {
                                            e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
                                        }
                                        break;
                                    default:
                                        {
                                            e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
                                        }
                                        break;

                                }
                                #endregion
                            }

                            BoundField bf = gv.Columns[i] as BoundField;
                            if (bf != null)
                            {
                                #region 存储值 转换成  显示值
                                switch (bf.DataField)
                                {
                                    case "STATUS":
                                        {
                                            temp = e.Row.Cells[i].Text.Trim();
                                            T_WORKORDERSTATUS_Entity entity =
                                                workOrderStatusBll.GetPageItem_T_WORKORDERSTATUS_EntityByKey(this.Page, StringHelper.ToInt(temp,0));

                                            if (entity != null)
                                            {
                                                temp = entity.ORDERSTATUSNAME;
                                                if (!String.IsNullOrEmpty(entity.RECORDSTYLE))
                                                {
                                                    e.Row.Attributes["style"] = entity.RECORDSTYLE;

                                                }
                                            }
                                            e.Row.Cells[i].Text = temp;
                                        }
                                        break;
                                    case "ProcessingObjectType":
                                        {
                                            temp = e.Row.Cells[i].Text.Trim();
                                            temp = ((UserType) Enum.Parse(typeof (UserType), temp)).ToString();
                                            e.Row.Cells[i].Text = temp;
                                        }
                                        break;
                                    default:
                                        {

                                        }
                                        break;
                                }
                                #endregion
                            }
                        }
                        #region 超期样式
                        DateTime dt = DateTime.Now;
                        temp = (gv.DataKeys[e.Row.RowIndex].Values["ToDoReminderTime"] == null)
                                   ? "" : gv.DataKeys[e.Row.RowIndex].Values["ToDoReminderTime"].ToString();
                        if (DateTime.TryParse(temp, out dt))
                        {
                            if (dt.CompareTo(DateTime.Now) < 0)
                            {
                                try
                                {
                                    e.Row.Attributes["style"] = configBll.GetCacheValueByName(this.Page, "ExtendedStyle");
                                }
                                catch (Exception)
                                {

                                }
                            }
                        }
                        #endregion
                    }
                    break;
                case DataControlRowType.Header:
                    {

                    }
                    break;
                case DataControlRowType.Pager:
                    {

                    }
                    break;
                case DataControlRowType.EmptyDataRow:
                    {


                    }
                    break;
                default:

                    break;
            }

        }

        /// <summary>
        /// GridView 行创建事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_RowCreated(object sender, GridViewRowEventArgs e)
        {
            switch (e.Row.RowType)
            {
                case DataControlRowType.DataRow:
                    {

                    }
                    break;
                case DataControlRowType.Header:
                    {

                    }
                    break;
                case DataControlRowType.Pager:
                    {

                    }
                    break;
                case DataControlRowType.EmptyDataRow:
                    {


                    }
                    break;
                default:

                    break;
            }

        }
        #endregion

    }
}
